package com.xunwulian.cmeb.command;

import com.xunwulian.base.exception.ErrorCodeException;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class BatchSmsUsedCommand extends Command {

    private List<String> msisdn = null;
    private String queryDate;

    public BatchSmsUsedCommand(Receiver receiver, List<String> msisdn, String queryDate) {
        super(APICode.GPRSUSEDBYDATEBATCH, receiver);
        this.msisdn = msisdn;
        this.queryDate = queryDate;
    }

    @Override
    public String getParam() {
        return "msisdns=" + StringUtils.collectionToDelimitedString(msisdn, "_") + "&query_date=" + queryDate;
    }

    @Override
    public HashMap<String, String> execute() throws ErrorCodeException {
        JSONArray result = receiver.actionPost(api, getParam());

        HashMap<String, String> map = new HashMap();
        if (null != result && result.length() != 0) {

            //TODO(liyankai) : comment
//            Iterator iter = result.iterator();
//            while (iter.hasNext()) {
//                JSONObject jsonObject = (JSONObject) iter.next();
//                map.put(jsonObject.getString("msisdn"), jsonObject.getString("sms"));
//            }
        }
        return map;
    }
}
